package com.cfuture08.home.action.user;

import com.cfuture08.eweb4j.component.dwz.DWZUtil;
import com.cfuture08.eweb4j.mvc.action.Action;
import com.cfuture08.eweb4j.mvc.action.ActionSupport;
import com.cfuture08.eweb4j.orm.dao.DAO;
import com.cfuture08.home.vo.User;
import com.cfuture08.util.StringUtil;

public class AddUser extends ActionSupport {
	private User user;

	public String execute() {
		if (DAO.selectOne(user, new String[] { "account" }) != null) {
			out.print(DWZUtil.getFailedJson("添加用户" + user.getAccount()
					+ "失败,该用户账号已经存在"));
		} else if (DAO.selectOne(user, new String[] { "nickName" }) != null) {
			out.print(DWZUtil.getFailedJson("添加用户" + user.getNickName()
					+ "失败,该用户昵称已经存在"));
		} else {
			user.setRegTime(StringUtil.getNowTime());
			out.print(DAO.insert(user) == true ? DWZUtil.getSuccessJson("添加用户"
					+ user.getAccount() + "成功", "xssyyh", "showAllUser.do",
					null) : DWZUtil.getFailedJson("添加用户" + user.getAccount()
					+ "失败"));
		}

		return Action.AJAX;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}
